<template>
  <div class="content">
    <div class="tableBox posting_box_list">
      <el-table :data="tableData" stripe style="width: 100%" v-loading="loading" border>
        <template v-for="(item,index) in allData">
          <el-table-column
            :key="index"
            :prop="item.value"
            v-if="item.value!=='opt'"
            :label="item.label"
            align="center"
          ></el-table-column>
          <el-table-column
            :key="item.value"
            v-if="item.value=='opt' && type == 1 "
            label="操作"
            min-width="100px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button @click="lookLog(scope.row)" type="text" size="small">查看日志</el-button>
              <el-button
                @click="check(scope.row)"
                type="text"
                size="small"
                v-if="global.powerAllBtn.qygl.qyxxshBtn && type == 1"
              >审核</el-button>
              <!-- <el-button v-show="scope.row.remark === '1'" type="text" size="small" @click="remove(scope.row)">下架</el-button> -->
              <el-button
                type="text"
                size="small"
                @click="toReport(scope.row,reportStatus)"
                v-show="global.powerAllBtn.qygl.qyxxsbBtn && type == 1"
              >上报</el-button>
            </template>
          </el-table-column>

          <el-table-column
            :key="item.value"
            v-if="item.value=='opt' && type == 2"
            label="操作"
            min-width="100px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button @click="lookLog(scope.row)" type="text" size="small">查看日志</el-button>
              <el-button
                @click="check(scope.row)"
                type="text"
                size="small"
                v-if="global.powerAllBtn.qygl.zmqyshBtn && type == 2"
              >审核</el-button>
              <!-- <el-button v-show="scope.row.remark === '1'" type="text" size="small" @click="remove(scope.row)">下架</el-button> -->
              <el-button
                type="text"
                size="small"
                @click="toReport(scope.row,reportStatus)"
                v-if="global.powerAllBtn.qygl.zmqysbBtn && type == 2"
              >上报</el-button>
            </template>
          </el-table-column>
          <el-table-column
            :key="item.value"
            v-if="item.value=='opt'  && type == 3"
            label="操作"
            min-width="100px"
            align="center"
          >
            <template slot-scope="scope">
              <el-button @click="lookLog(scope.row)" type="text" size="small">查看日志</el-button>
              <el-button
                @click="check(scope.row)"
                type="text"
                size="small"
                v-show="global.powerAllBtn.qygl.yzqyshBtn && type == 3"
              >审核</el-button>
              <!-- <el-button v-show="scope.row.remark === '1'" type="text" size="small" @click="remove(scope.row)">下架</el-button> -->
              <el-button
                type="text"
                size="small"
                @click="toReport(scope.row,reportStatus)"
                v-show="global.powerAllBtn.qygl.yzqyshBtn && type == 3"
              >上报</el-button>
            </template>
          </el-table-column>
        </template>
      </el-table>
    </div>
    <div style="padding:20px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="ScheduleCurrentChange"
        :current-page="pages.pagenum"
        :page-sizes="[10,20, 30, 50,100]"
        :page-size="pages.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pages.total"
        background
      ></el-pagination>
    </div>
    <el-dialog :visible.sync="checkFlag" width="980px" custom-class="jhdialog">
      <check
        v-if="checkFlag"
        :companyName="info.companyname"
        :companyId="info.id"
        :tabNum="current"
        :type="companyType"
        @cancelCheck="close"
      ></check>
    </el-dialog>
    <el-dialog :visible.sync="warnDialogVisible" width="500px" @close="closeWarnDialog">
      <div class="warn-dialog-header">
        <span>上报原因</span>
      </div>
      <div class="warn-dialog-body">
        <div class="warn-dialog-body-title">发送内容</div>
        <el-input type="textarea" :rows="6" v-model.trim="reportContent"></el-input>
        <div class="warn-dialog-btn">
          <el-button style="margin-right: 30px;" @click="warnDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="confirmReport">确定</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog :visible.sync="showLog" width="1024px" custom-class="showlog">
      <showLog :reportid="reportId"></showLog>
    </el-dialog>
  </div>
</template>
<script>
import check from "../../socical/socialCheck/check.vue";
import showLog from "../showLog.vue";
export default {
  data () {
    return {
      checkFlag: false, //是否显示审核详情

      info: {}, //传给子组件的公司信息
      current: "0",

      tableData: [],
      loading: false,
      allData: [],
      currentType: '',
      pages: {
        pagesize: 10,
        total: 0,
        pagenum: 0,
      },
      warnDialogVisible: false,//上报弹窗
      reportContent: '',//上报原因
      companyType: '',//上报type
      reportId: '',//上报id
      reportStatus: "",
      showLog: false
    }
  },
  props: ['type'],
  components: {
    check,
    showLog
  },
  created () {
    this.global = this.GLOBAL;
    this.getData();
  },
  methods: {
    //获取列表
    getData () {
      if (!this.type) {
        return;
      }

      this.currentType = this.type;
      this.getAllData(this.type);
      if (this.type == 1) {
        this.reportStatus = 1;
      } else if (this.type == 2) {
        this.reportStatus = 2;
      } else if (this.type == 3) {
        this.reportStatus = 3;

      }
      this.loading = true;
      let obj = {
        pagenum: this.pages.pagesize,
      }
      this.$axios.post('/app/v1/platform/unusual/todoList', {
        "type": this.type,
        pagesize: this.pages.pagesize,
        pagenum: this.pages.pagenum
      }).then(resp => {
        if (resp.data.message === 'success.') {
          this.tableData = resp.data.data.list;
          this.pages.total = Number(resp.data.data.totalnum);
          this.pages.pagesize = Number(resp.data.data.pagesize);
          this.loading = false;

        }
      })
    },

    getAllData (type) {
      if (type == 1) {
        this.allData = [
          {
            label: "企业名称",
            value: "companyname"
          },
          {
            label: "所在地区",
            value: "address"
          },
          {
            label: "企业类型",
            value: "companytype"
          },
          {
            label: "企业规模",
            value: "companysize"
          },
          {
            label: "注册时间",
            value: "registertime"
          },
          {
            label: "操作",
            value: "opt"
          }
        ]
      } else if (type == 2) {
        this.allData = [
          {
            label: "企业名称",
            value: "companyname"
          },
          {
            label: "所在地区",
            value: "address"
          },
          {
            label: "企业类型",
            value: "companytype"
          },
          {
            label: "企业规模",
            value: "companysize"
          },
          {
            label: "申请时间",
            value: "releasetime"
          },
          {
            label: "操作",
            value: "opt"
          }
        ]
      } else if (type == 3) {
        this.allData = [
          {
            label: "企业名称",
            value: "companyname"
          },
          {
            label: "所在地区",
            value: "address"
          },
          {
            label: "企业类型",
            value: "companytype"
          },
          {
            label: "企业规模",
            value: "companysize"
          },
          {
            label: "申请时间",
            value: "releasetime"
          },
          {
            label: "操作",
            value: "opt"
          }
        ]
      }

    },
    //审核不通过
    // 审核
    check (r) {
      this.info = r;
      this.checkFlag = true;
      if (this.type == 1) {
        this.companyType = 1;
      } else if (this.type == 2) {
        this.companyType = 3;
      } else if (this.type == 3) {
        this.companyType = 2;

      }
      this.reportId = r.reportid;
    },
    //上报
    toReport (r, type) {
      this.warnDialogVisible = true;
      this.reportType = type;
      this.reportContent = '';
      this.reportId = r.reportid;
    },
    close () {
      this.checkFlag = false;
      this.getData(this.companyType);
    },
    //上报里确定
    confirmReport () {
      if (!this.reportContent) {
        this.$message({
          type: "warning",
          message: "上报内容不能为空!"
        });
        return;
      }
      let currentData = {
        reportid: this.reportId,
        status: 0,
        content: this.reportContent || ''
      }
      this.reportCall(currentData)
    },
    //待办提交
    reportCall (data) {
      this.$axios.post('app/v1/platform/unusual/todoHandleSubmit',
        data
      ).then(resp => {
        if (resp.data.message === 'success.') {
          // this.tableData = resp.data.data;
          // this.pages.total = resp.data.data.length;
          this.loading = false;
        } else {
          this.$message({
            message: resp.data.message,
            type: "error"
          });
        }
        this.warnDialogVisible = false;
        this.getData();
      })

    },
    handleSizeChange (val) {
      this.pages.pagenum = 1;
      this.pages.pagesize = val;
      this.getData();
    },
    //分页查询
    ScheduleCurrentChange (val) {
      this.pages.pagenum = val;
      this.getData();
    },
    reportCallback (currentData) {
      var data = {
        reportid: this.reportId,
        status: currentData.status,
        content: currentData.content || ''
      }
      this.$emit('reportCallback', data)
    },
    closeWarnDialog () {
      this.reportContent = "";
    },
    lookLog (row) {
      this.reportId = row.reportid;
      this.showLog = true;
    }
  },
  watch: {
    type (newVal, oldVal) {
      this.getData();
    }
  }

}
</script>
<style>
/* 上报原因样式 */
.warn-dialog-header {
  font-size: 16px;
  box-sizing: border-box;
  padding: 20px;
  border-bottom: 1px solid #bfbfbf;
}

.warn-dialog-header::before {
  content: "";
  border-left: 8px solid #0064e4;
  margin-right: 10px;
}

.warn-dialog-body {
  box-sizing: border-box;
  padding: 20px;
}

.warn-dialog-body-title {
  font-size: 16px;
  margin-bottom: 20px;
}

.warn-dialog-btn {
  margin-top: 20px;
  text-align: center;
}
</style>


